﻿using NPOI.SS.UserModel;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Abp.NPOI
{
    public class NPOIRowElement
    {
        /// <summary>
        /// 
        /// </summary>
        public ISheet Sheet { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public IRow Row { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public int RowIndex { get; set; }

        public const int HeightConstant = 20;


        public NPOIRowElement(ISheet sheet, int rowIndex)
        {
            this.Sheet = sheet;
            this.RowIndex = rowIndex;
            this.Row = this.Sheet.CreateRow(rowIndex);
            this.SetHeight(20);
        }

        public NPOIRowElement SetHeight(int height)
        {
            this.Row.Height = (short)(HeightConstant * height);
            return this;
        }

        internal static ICellStyle Style = null;
        /// <summary>
        /// 创建样式（在创建第一行之后调用）
        /// </summary>
        public  void CreateStyle()
        {
            if (Style == null)
            {
                Style = this.Row.Sheet.Workbook.CreateCellStyle();
                Style.BorderBottom = BorderStyle.Thin;
                Style.BorderLeft = BorderStyle.Thin;
                Style.BorderRight = BorderStyle.Thin;
                Style.BorderTop = BorderStyle.Thin;
                Style.VerticalAlignment = VerticalAlignment.Center;
                Style.Alignment = HorizontalAlignment.Center;
            }
            
        }
        /// <summary>
        /// 销毁样式（表格创建完成后调用）
        /// </summary>
        public void DestoryStyle()
        {
            Style = null;
        }

    }
}
